package in.muton.edushare.documentModel.excel;

import org.apache.poi.ss.usermodel.Cell;

public class ExcelHelper {

	/**
	 * Takes a Excel Sheet cell and returns corresponding string.
	 * For blank, it returns null 
	 * For error or formula cells, it returns blank
	 * For Boolean, it returns 1 for true, 0 for otherwise
	 * For Numeric, it returns numeric casted in String
	 * For String, it returns the String entered.
	 * @param cell
	 * @return
	 */
	public static String getCellValueAsString(Cell cell) {
		if(cell==null)
			return null;
		
		int cellType = cell.getCellType();
		if(cellType == Cell.CELL_TYPE_FORMULA){
			cellType = cell.getCachedFormulaResultType();
		}
		
		switch (cellType) {
			case Cell.CELL_TYPE_BLANK:
				return "";
			case Cell.CELL_TYPE_BOOLEAN:
				return cell.getBooleanCellValue()?"1":"0";
			case Cell.CELL_TYPE_NUMERIC:
				return cell.getNumericCellValue()+"";
			case Cell.CELL_TYPE_STRING:
				return cell.getStringCellValue();
			default:
				return "";
		}
	}

	/*private static String getPrecalculatedResule(Cell cell) {
		switch (cell.getCachedFormulaResultType()) {
		case Cell.CELL_TYPE_BLANK:
			return "";
		case Cell.CELL_TYPE_BOOLEAN:
			return cell.getBooleanCellValue()?"1":"0";
		case Cell.CELL_TYPE_NUMERIC:
			return cell.getNumericCellValue()+"";
		case Cell.CELL_TYPE_STRING:
			return cell.getStringCellValue();
		default:
			return "";
		}
	}*/

}
